/*! 
 * Header file for a spring force generator.
 *
 * \author Devis Rossini
 * \date 19 March 2012
 */ 
#ifndef PHXSPRINGFORCEGENERATOR_H_INCLUDE_GUARD
#define PHXSPRINGFORCEGENERATOR_H_INCLUDE_GUARD

#include "PhxCore.h"
#include "PhxForceGenerator.h"

namespace phx
{
	/*!
     * A force generator that applies a spring force.
     */
    class Spring : public ForceGenerator
    {
    public:

        /*! Creates a new spring with the given parameters. */
        Spring(const Vector3& localConnectionPoint,
               RigidBody* otherBody,
               const Vector3& otherConnectionPoint,
               real springConstant,
               real restLength);

        /*! Applies the spring force to the given rigid body. */
        virtual void UpdateForce(RigidBody* body, real duration);

	private:

		/*!
         * The point of connection of the spring, in local
         * coordinates.
         */
        Vector3 mConnectionPoint;

        /*!
         * The point of connection of the spring to the other object,
         * in that object's local coordinates.
         */
        Vector3 mOtherConnectionPoint;

        /*! The body at the other end of the spring. */
        RigidBody* mOtherBody;

        /*! Holds the sprint constant. */
        real mSpringConstant;

        /*! Holds the rest length of the spring. */
        real mRestLength;
    };
}

#endif // PHXSPRINGFORCEGENERATOR_H_INCLUDE_GUARD